package org.sbbs.base.tenant.manager.impl;

import jakarta.annotation.PostConstruct;
import java.util.List;
import org.sbbs.base.jpa.manager.impl.BaseManagerImpl;
import org.sbbs.base.tenant.dao.TenantDSRepo;
import org.sbbs.base.tenant.entity.TenantDS;
import org.sbbs.base.tenant.manager.TenantDSManager;
import org.sbbs.base.tenant.tenancy.SbbsTenantRoutingDatasource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jenkins
 */
@Service
//@Qualifier("multiTenantDemoEntityManager")
public class TenantDSManagerImpl extends BaseManagerImpl<TenantDS, Long, TenantDSRepo> implements TenantDSManager {

    @Autowired
    private TenantDSRepo tenantDSRepo;
    @Autowired
    private SbbsTenantRoutingDatasource tenantRoutingDatasource;

    @PostConstruct
    public void init() {
        super.setRepo(tenantDSRepo);
        List<TenantDS> l = this.tenantDSRepo.findAll();

        this.tenantRoutingDatasource.initTenantDs(l);
        this.tenantRoutingDatasource.afterPropertiesSet();
    }

}
